#include<iostream>
using namespace std;
int main()

{
    int n;
    while(cin>>n)
    {
       if(n==1) {cout<<n<<endl;continue;}
       if(n==0) break;
       else if(n%2==0||n%3==0||n%5) cout<<n<<endl; 
    }
    system("pause");
    return 0;
}
       
